<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Country of Residence</title>
</head>
<body>

    <!--  Book keeping for residence.jsp -->
    <% 
      String residence = request.getParameter("residence"); 
      // sets country as session attribute
      session.setAttribute("residence", residence);
      // flag for degrees loop to make sure they don't reprocess the addres each time
      session.setAttribute("degreeFlag", "false");
    %>
    
    
    <!-- User Prompts for country of residence -->
    Welcome, <%= (session.getAttribute("first") + " " +
                  session.getAttribute("middle") + " " + 
                  session.getAttribute("last")) %>! <br>
    From <%= session.getAttribute("citizen") %> <br>
    Living in <%= session.getAttribute("residence") %>

    
    <% 
    // processes which path the user will take after submit
    String path;
    // If US citizen, go directly to degree.jsp
    if(residence.equals("United States")){
        path = "degree.jsp";
    }else{
        path = "residency.jsp";
    }
    %>
    
    <!--  Processing of address -->
    <form METHOD="GET" action=<% out.print("\"" + path + "\""); %>>
        <!-- Address fields -->
        Address: <input type="text" size="20" name="address" maxlength="20" /><br>
        City: <input type="text" size="20" name="city" maxlength="20"/><br>
        <%
        // only need state field if in US
        if(residence.equals("United States")){
            out.print("State: <input type=\"text\" size=\"3\" name=\"state\"maxlength=\"20\"/><br>");
        }
        %>
        Zip Code: <input type="text" size="5" name="zip" maxlength="5"/><br>
        <%
        // only have telephone code if non us
        if(!residence.equals("United States")){
            out.print("Telephone Code: <input type=\"text\" size=\"6\" name=\"telecode\"maxlength=\"6\"/><br>");
        }
        %>        
        Area Code: <input type="text" size="4" name="area" maxlength="5"/>
        Number: <input type="text" size="10" name="number" maxlength="9"/><br>
        <input type=submit name="Submit"/>
    </form>
    

</body>
</html>